Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Replace _execute_error() with _execute_or_fail(). #42

Merged
merged 1 commit into from
Nov 13, 2018

Conversation

mboes
Copy link
Member

@mboes mboes commented Nov 13, 2018

This refactor has two simple goals:

  • Simplify control flow: callers no longer need to if-then-else
    themselves, which becomes cumbersome when you have a sequence of
    calls to repository_ctx.execute().
  • Improve the output on failure (by listing the failing command).

This refactor has two simple goals:

* Simplify control flow: callers no longer need to `if-then-else`
  themselves, which becomes cumbersome when you have a sequence of
  calls to `repository_ctx.execute()`.
* Improve the output on failure (by listing the failing command).
@mboes mboes requested a review from Profpatsch November 13, 2018 13:40
Copy link
Contributor

@Profpatsch Profpatsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn’t want to assume that 0 always means success (or that non-zero always means failure), but as long as we don’t have that case, we can factor it out I guess.

@@ -142,6 +145,26 @@ def nixpkgs_package(*args, **kwargs):
else:
_nixpkgs_package(*args, **kwargs)

def _execute_or_fail(repository_ctx, arguments, failure_message = "", *args, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does *args work after failure_message=? I’m forgot most of the details of this pythonism.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

@mboes
Copy link
Member Author

mboes commented Nov 13, 2018

0 should always mean success. This convention is followed so universally that I don't think we need to pessimize our code readability just in case.

@mboes mboes merged commit 99b15cb into master Nov 13, 2018
@mboes mboes deleted the execute-or-fail branch November 13, 2018 17:59
mboes added a commit that referenced this pull request Nov 13, 2018
A parenthesis was in the wrong place.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants